﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BrokerBase.Lib.Policy;

namespace broker.duty.TP
{
    class Class2
    {
        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.SchemePeriodActing.InsurantStates.Contains("住院"))
            {
                int day = Convert.ToInt32(ppa.SchemePeriodActing.SchemeActing.GetAuxConfigValue("住院天数"));

                double a = ppa.Amount * 1250 - ppa.TotalValue;

                double f = ppa.Amount * day;

                if (f >= a)
                {
                    da.Value = a ;
                    ppa.IsCurrentFinish = true;
                }
                else
                {
                    da.Value = f;
                }

            }
        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.SchemePeriodActing.InsurantStates.Contains("重症监护"))
            {
                int day = Convert.ToInt32(ppa.SchemePeriodActing.SchemeActing.GetAuxConfigValue("重症监护天数"));

                double a = ppa.PolicyActing.Policy.Amount * 1250 -ppa.TotalValue;

                double f = ppa.Amount * day * 2;

                if (f >= a)
                {
                    da.Value = a ;
                    ppa.IsCurrentFinish = true;
                }
                else
                {
                    da.Value = f;
                }

                ppa.SchemePeriodActing.InsurantStates.Add("住院");
            }
        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.SchemePeriodActing.InsurantStates.Contains("重症监护"))
            {
                int day = Convert.ToInt32(ppa.SchemePeriodActing.SchemeActing.GetAuxConfigValue("重症监护天数"));

                da.Value = ppa.Amount * day * 2;
            }
        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.SchemePeriodActing.InsurantStates.Contains("身故"))
            {
                da.Value = ppa.SchemePeriodActing.BasicPolicyPeriodActing.Amount * 1250;
                ppa.IsCurrentFinish = true;
                ppa.SchemePeriodActing.BasicPolicyPeriodActing.IsCurrentFinish = true;
            }
        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {


            if (ppa.SchemePeriodActing.InsurantStates.Contains("门急症") || ppa.SchemePeriodActing.InsurantStates.Contains("住院"))
            {
                double fee = Convert.ToDouble(ppa.SchemePeriodActing.SchemeActing.GetAuxConfigValue("门急诊住院费用"));

                double a = ppa.Amount * 1250 - ppa.TotalValue;

                double f = ppa.Amount * 50;

                if (ppa.Age >= 60 && ppa.Age < 75)
                {
                    double x = fee > f ? f : fee;

                    if (x >= a)
                    {
                        da.Value = a;
                        ppa.IsCurrentFinish = true;
                    }
                    else
                    {
                        da.Value = x;
                    }
                }
                else if (ppa.Age >= 75)
                {


                    if (fee >= a)
                    {
                        da.Value = a;
                        ppa.IsCurrentFinish = true;
                    }
                    else
                    {
                        da.Value = fee;
                    }
                }

            }
        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {


            if (ppa.SchemePeriodActing.InsurantStates.Contains("门急症") || ppa.SchemePeriodActing.InsurantStates.Contains("住院"))
            {
                double fee = Convert.ToDouble(ppa.SchemePeriodActing.SchemeActing.GetAuxConfigValue("门急诊住院费用"));

                double a = ppa.Amount * 1250 - ppa.TotalValue;

                double f = ppa.Amount * 50;

                da.Value = fee;

            }
        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.SchemePeriodActing.InsurantStates.Contains("重大手术"))
            {
                double a = ppa.Amount * 1250 - ppa.TotalValue;
                double f = ppa.Amount * 50;

                if (f >= a)
                {
                    da.Value = a;
                    ppa.IsCurrentFinish = true;
                }
                else
                {
                    da.Value = f;
                }

            }
        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.Period > 0)
            {
                IPolicyPeriodActing pppa = ppa.PolicyActing.PeriodActings[ppa.Period - 1];

                if (pppa.SchemePeriodActing.InsurantStates.Contains("重疾") || pppa.SchemePeriodActing.InsurantStates.Contains("全残"))
                {
                    ppa.Fee = 0;
                }
            }
        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.Period>0 &&  ppa.Period  % 5 == 0 && ppa.Period <= 20)
            {
                double t = 0;
                for (int i = 1; i <= 5; i++)
                {
                    IPolicyPeriodActing pppa = ppa.PolicyActing.PeriodActings[ppa.Period - i];
                    t += pppa.Value;
                    if (t > 0)
                        break;
                }

                if(t<=double.Epsilon)
                {
                    ppa.Amount += ppa.Amount * 0.05;
                }
            }
        }


        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.SchemePeriodActing.InsurantStates.Contains("身故"))
            {
                da.Value = ppa.Amount;
                ppa.IsCurrentFinish = true;
               
            }
        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.Age == 25)
            {
                da.Value = ppa.Amount;
                ppa.IsCurrentFinish = true;
            }
        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {

            if (ppa.Period>0 )
            {
                IPolicyPeriodActing pppa = ppa.PolicyActing.PeriodActings[ppa.Period - 1];

                if (pppa.SchemePeriodActing.HolderStates.Contains("身故") || pppa.SchemePeriodActing.HolderStates.Contains("全残"))
                {
                    ppa.Fee = 0;
                }                
            }
        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.SchemePeriodActing.InsurantStates.Contains("身故"))
            {
                if (ppa.Age < 18)
                {
                    da.Value = ppa.TotalFee;
                    da.Description = "如果现金价值较大则支付现金价值";
                }
                else
                {
                    da.Value = ppa.Amount;
                }
                ppa.IsCurrentFinish = true;

            }
        }

        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.SchemePeriodActing.InsurantStates.Contains("特种重疾"))
            {
                ppa.SchemePeriodActing.InsurantStates.Add("重疾");
                da.Value = ppa.Amount * 0.3;
            }
        }

    }
}
